package com.example.demo.service;

import com.example.demo.listener.WorkApplicationEvent;
import com.example.demo.entity.MyEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

@Service
public class PublishService {
    @Autowired
    private  ApplicationEventPublisher applicationEventPublisher;

    public String testEvent() {
        MyEvent workEvent = new MyEvent();
        workEvent.setMessage("可以开始静态预警了");
        WorkApplicationEvent event = new WorkApplicationEvent(workEvent);
        System.out.println("推送监听事件");
        // 发布事件
        applicationEventPublisher.publishEvent(event);
        System.out.println("已推送成功");
        return "推送成功";
    }
}
